<template>
<div class="ich-main">
    <div class="page-header">
        <h1>弘扬非遗</h1>
        <p>传承中华优秀传统文化</p>
    </div>
    
    <div class="cards-container">
        <div class="ich-card" v-for="(ich, index) in tableData" :key="index" @click="detail(index)">
            <div class="card-image">
                <img :src="ich.ichPicture" :alt="ich.ichName" />
                <div class="card-overlay">
                    <el-button type="primary" size="small" @click.stop="viewDetail(ich, index)">查看详情</el-button>
                </div>
            </div>
            <div class="card-content">
                <h3 class="card-title">{{ ich.ichName }}</h3>
                <div class="card-info">
                    <p class="info-item">
                        <i class="el-icon-user"></i>
                        {{ ich.ichAuthor }}
                    </p>
                    <p class="info-item">
                        <i class="el-icon-time"></i>
                        {{ ich.ichDate }}
                    </p>
                    <p class="info-item desc-text">
                        <i class="el-icon-s-ticket"></i>
                        {{ ich.ichDesc }}
                    </p>
                </div>
            </div>
        </div>
    </div>

    <!-- 详情对话框 -->
    <el-dialog
        title="非遗详情"
        :visible.sync="detailVisible"
        width="600px"
        :before-close="handleClose">
        <div class="detail-dialog" v-if="selectedIch">
            <div class="detail-image">
                <img :src="selectedIch.ichPicture" :alt="selectedIch.ichName" />
            </div>
            <div class="detail-content">
                <h2>{{ selectedIch.ichName }}</h2>
                <div class="detail-info">
                    <p><i class="el-icon-user"></i> 发布者：{{ selectedIch.ichAuthor }}</p>
                    <p><i class="el-icon-time"></i> 发布时间：{{ selectedIch.ichDate }}</p>
                    <p><i class="el-icon-s-ticket"></i> 非遗介绍：{{ selectedIch.ichDesc }}</p>
                </div>
            </div>
        </div>
        <span slot="footer" class="dialog-footer">
            <el-button @click="detailVisible = false">关 闭</el-button>
        </span>
    </el-dialog>
</div>
</template>

<script>
const axios = require('axios')
const qs = require('qs')
const ele = require('element-ui')

export default {
    name: 'ich_page',
    data() {
        return {
            ichID: '',
            ichName: '',
            ichDesc: '',
            ichAuthor: '',
            ichDate: '',
            ichPicture: '',
            tableData: [],
            detailVisible: false,
            selectedIch: null
        }
    },
    methods: {
        detail(index) {
            this.ichID = this.tableData[index].ichID
            this.ichName = this.tableData[index].ichName
            this.ichDesc = this.tableData[index].ichDesc
            this.ichPicture = this.tableData[index].ichPicture
            this.ichAuthor = this.tableData[index].ichAuthor
            this.ichDate = this.tableData[index].ichDate
        },
        viewDetail(ich, index) {
            this.selectedIch = ich;
            this.detailVisible = true;
        },
        handleClose(done) {
            this.detailVisible = false;
            this.selectedIch = null;
            if (done) done();
        }
    },
    created() {
        let _this = this
        this.userName = window.localStorage.getItem('userName')
        axios({
            method: 'get',
            url: 'http://localhost:8080/getIchList',
            headers: {
                'Content-type': 'application/x-www-form-urlencoded'
            }
        }).then(function (response) {
            _this.tableData = response.data.dataList
        }).catch(function (error) {
            console.log(error)
        })
    }
};
</script>

<style scoped>
.ich-main {
    min-height: 100vh;
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    padding: 40px 20px;
}

.page-header {
    text-align: center;
    margin-bottom: 40px;
    color: white;
}

.page-header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    font-weight: 700;
}

.page-header p {
    font-size: 1.2rem;
    opacity: 0.9;
}

.cards-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 30px;
    max-width: 1200px;
    margin: 0 auto;
}

.ich-card {
    background: white;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    cursor: pointer;
}

.ich-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.card-image {
    position: relative;
    height: 200px;
    overflow: hidden;
}

.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.ich-card:hover .card-image img {
    transform: scale(1.05);
}

.card-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.ich-card:hover .card-overlay {
    opacity: 1;
}

.card-content {
    padding: 20px;
}

.card-title {
    font-size: 1.3rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 15px;
    line-height: 1.4;
}

.card-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.info-item {
    display: flex;
    align-items: flex-start;
    color: #666;
    font-size: 0.9rem;
    margin: 0;
}

.info-item i {
    color: #42b983;
    margin-right: 8px;
    width: 16px;
    margin-top: 2px;
}

.desc-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

/* 详情对话框样式 */
.detail-dialog {
    display: flex;
    gap: 20px;
}

.detail-image {
    flex: 1;
}

.detail-image img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: 8px;
}

.detail-content {
    flex: 1;
}

.detail-content h2 {
    margin: 0 0 15px 0;
    color: #333;
    font-size: 1.5rem;
}

.detail-info p {
    margin: 10px 0;
    color: #666;
    line-height: 1.6;
    display: flex;
    align-items: flex-start;
}

.detail-info i {
    color: #42b983;
    margin-right: 8px;
    width: 16px;
    margin-top: 2px;
}

.el-dialog {
    border-radius: 8px;
}

/* 响应式设计 */
@media (max-width: 1024px) {
    .cards-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .cards-container {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .page-header h1 {
        font-size: 2rem;
    }
    
    .page-header p {
        font-size: 1rem;
    }
    
    .detail-dialog {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .ich-main {
        padding: 20px 10px;
    }
}
</style>
